<?php

class Admin_ExcursionController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Excursion.php');
        $excursion_model = new Excursion();
        $excursion_arr = $excursion_model->listExcursions();
        // print_r($newsletter_arr); EXIT;
        $this->view->excursion_arr = $excursion_arr;
     //  print_r($excursion_arr); EXIT;
    }

     public function editAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Excursion.php');
        $excursion_model = new Excursion();
        $excursion_id = $this->_getParam('id', 0);
        $excursion_arr = $excursion_model->getexcursionbyid($excursion_id);
   //      print_r($excursion_arr); EXIT;
        $this->view->excursion_arr = $excursion_arr;
         $this->view->excursion_id=$excursion_id;
     //  print_r($excursion_arr); EXIT;
    }
     public function doeditAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Excursion.php');
        $excursion_model = new Excursion();
         $request = $this->getRequest();
        if ($this->getRequest()->isPost()) {
			$excursion_model = new Excursion();
			$form_values = $request->getPost();
                        $update_excursion = $excursion_model->updateExcursion($form_values);
		}
     //  print_r($excursion_arr); EXIT;
    }


    public function addAction()
    {
        $this->_helper->layout()->disableLayout();
     //  print_r($excursion_arr); EXIT;
    }
    
    public function doaddAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Excursion.php');
        $excursion_model = new Excursion();
         $request = $this->getRequest();
        if ($this->getRequest()->isPost()) {
			$excursion_model = new Excursion();
			$form_values = $request->getPost();
			$update_excursion = $excursion_model->addExcursion($form_values);
		}
    }

    

   	public function updateExcursionAction()
   	{
   		$this->_helper->layout()->disableLayout();
   		Zend_Loader::loadFile('../application/admin/models/Excursion.php');
		Zend_Loader::loadFile('../application/admin/forms/Excursion.php');
        $rate_form = new Form_Excursion();
        $request = $this->getRequest();
        if ($this->getRequest()->isPost()) {            
			$rate_model = new Excursion();
			$form_values = $request->getPost();
			$update_Excursion = $rate_model->updateRate($form_values);
		}
		
		exit;
   	}
    
	public function deleteexcursionAction()
    {
        $this->_helper->layout()->disableLayout();
        $id = $this->_getParam('id', 0);
        Zend_Loader::loadFile('../application/admin/models/Excursion.php');
        $excursion_model = new Excursion();
        $excursion_model->deleteExcursion($id);
        //$this->_helper->redirector('index');
        exit;
    }

    public function excursionfeaturesAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Excursion.php');
        $excursion_model = new Excursion();
        $controller = $this->getRequest()->getControllerName();
        $action = $this->getRequest()->getActionName();
        $this->view->title = "Add new Rate";
        $id = $this->_getParam('id', 0);
        $options = array("action"=>$action, "rate_id"=>$rate_id);
        $structarr=$excursion_model->getexcursionfeatures($id);
     // print_r($structarr);
        $this->view->structarr = $structarr;
        $this->view->id = $id;

        
    }

     public function doaddexcursionfeaturesAction()
    {
         $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Excursion.php');
        $rate_model = new Excursion();
        $controller = $this->getRequest()->getControllerName();
        $action = $this->getRequest()->getActionName();
         if ($this->getRequest()->isPost()) {
			$rate_model = new Excursion();
			$form_values = $this->getRequest()->getPost();
                 //     print_r($form_values);exit;
                $elementarray=array();
                $exval=array();
                $exval_ru=array();
                $exkey=array();
                $i=0;
                foreach($form_values as $x){
                  foreach($x as $y){
                      switch($y["name"]){
                          case "exkey":
                              $exkey[]=$y["value"];
                               break;
                          case "exval":
                              $exval[]=$y["value"];
                               break;
                         case "exval_ru":
                              $exval_ru[]=$y["value"];
                               break;
                          case "id":
                              $elementarray["id"]=$y["value"];


                      }
                  }
                }

                foreach($exkey as $structkeyoptkey=>$structkeyoptval){
                    $elementarray["exkey"][$structkeyoptkey]=$exkey[$structkeyoptkey];
                    $elementarray["exval"][$structkeyoptkey]=$exval[$structkeyoptkey];
                    $elementarray["exval_ru"][$structkeyoptkey]=$exval_ru[$structkeyoptkey];

                }

             // print_r($elementarray);exit;
		$update_Excursion = $rate_model->updateexcursionfeatures($elementarray);
          }

           exit;

    }

    public function deletestructuredataAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Excursion.php');
        $excursion_model = new Excursion();
        $controller = $this->getRequest()->getControllerName();
        $action = $this->getRequest()->getActionName();
         if ($this->getRequest()->isPost()) {
             $form_values = $this->getRequest()->getPost();
             $deletestrdata = $excursion_model->deleteexcursionfeatures($form_values);
         }
         
    }
}